import globals from "globals";
import pluginJs from "@eslint/js";
import pluginVue from "eslint-plugin-vue";
import pluginTypeScript from "@typescript-eslint/eslint-plugin";

import parserVue from "vue-eslint-parser";
import parserTypeScript from "@typescript-eslint/parser";

import pluginPrettier from "eslint-plugin-prettier";

import fs from "fs";
const autoImportConfig = JSON.parse(fs.readFileSync(".eslintrc-auto-import.json", "utf-8"));

/** @type {import('eslint').Linter.Config[]} */
export default [
  {
    files: ["**/*.{js,mjs,cjs,ts,vue}"], // 只校验项目自身的 JS/TS/Vue 文件
    ignores: [
      "**/*.d.ts", // 原有忽略：TypeScript 声明文件
      // 新增：忽略 WebUploader 单个文件（路径完全匹配你的文件位置）
      "public/admin/components/ueditor/third-party/webuploader/webuploader.js",
      // 可选：忽略整个 UEditor 第三方库目录（避免后续其他第三方文件报错）
      //"public/admin/components/ueditor/third-party/**/*",
      // 新增：忽略 UEditor 所有文件（包括子目录）
      //"public/admin/components/ueditor/**/*",
    ],
  },

  // 第二步：全局配置（保持不变）
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
        ...autoImportConfig.globals,
        ...{
          PageQuery: "readonly",
          PageResult: "readonly",
          OptionType: "readonly",
          ResponseData: "readonly",
          ExcelResult: "readonly",
          TagView: "readonly",
          AppSettings: "readonly",
          __APP_INFO__: "readonly",
        },
      },
    },
    plugins: { prettier: pluginPrettier },
    rules: {
      "no-unused-vars": [
        "error",
        {
          argsIgnorePattern: "^_",
          varsIgnorePattern: "^[A-Z0-9_]+$",
          ignoreRestSiblings: true,
        },
      ],
    },
  },

  // 后续 JavaScript/TypeScript/Vue 配置（保持不变）
  pluginJs.configs.recommended,
  {
    files: ["**/*.ts"],
    ignores: ["**/*.d.ts"],
    languageOptions: {
      parser: parserTypeScript,
      parserOptions: { sourceType: "module" },
    },
    plugins: { "@typescript-eslint": pluginTypeScript },
    rules: {
      ...pluginTypeScript.configs.strict.rules,
      "@typescript-eslint/no-explicit-any": "off",
      "@typescript-eslint/no-empty-function": "off",
      "@typescript-eslint/no-empty-object-type": "off",
    },
  },
  {
    files: ["**/*.vue"],
    languageOptions: {
      parser: parserVue,
      parserOptions: { parser: parserTypeScript, sourceType: "module" },
    },
    plugins: { vue: pluginVue, "@typescript-eslint": pluginTypeScript },
    processor: pluginVue.processors[".vue"],
    rules: {
      ...pluginVue.configs.recommended.rules,
      "vue/no-v-html": "off",
      "vue/multi-word-component-names": "off",
    },
  },
];
